package cool.qingqing.lambda;

/**
 * @author 高山青
 * @Date 2022/1/2  -   20:11
 */

import cool.qingqing.addInterface.A;
import cool.qingqing.compartor.CompartorTest;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;

/**
 * Lambda表达式冗余的情况处理
 * 简化写法有五种情况
 * 类名::方法名
 * 对象::方法名
 * 静态类::方法名
 *
 * 类名::new
 *
 * 数组::new
 *
 */
public class LambdaDemo05 {

	public static void main(String[] args) {
		//对于原有的方法这么写就有些冗余了
		int lambdaSum= lamdbaSum((a,b)->a+b);
		//简化写法,类名方法名
		LambdaDemo05 lambdaDemo05=new LambdaDemo05();
		 BiFunction<Integer,Integer,Integer> biFunction=LambdaDemo05::lamdbaSum;
		 //对象名::方法名的情况
		 BiFunction<Integer,Integer,Integer> biFunction01=lambdaDemo05::sum;

		 //静态类::方法名
		List<Integer> list=new ArrayList<>();
		list.add(1);list.add(12);list.add(6);list.add(3);
		System.out.println();
		list.forEach(System.out::print);
		Consumer<List<Integer>> consumer=Collections::sort;
		consumer.accept(list);
		System.out.println();
		list.forEach(System.out::print);
		System.out.println();

		//构造方法的情况
		Supplier<LambdaDemo05> supplier=LambdaDemo05::new;
		supplier.get().sum(11,12);

		//数组::数组构造
		Function<Integer,String[]> supplier1=String[]::new;
				System.out.println(supplier1.apply(5).length);

		int sum= biFunction.apply(1,10);
		System.out.println(lambdaSum+sum);
	}

	public LambdaDemo05() {
		System.out.println("打印构造方法！");
	}

	public static int lamdbaSum(BiFunction<Integer,Integer,Integer> biFunction){
		return biFunction.apply(1,10);
	}

	public static int lamdbaSum(int a,int b){
		return a+b;
	}
	public  int sum(int a,int b){
		return a+b;
	}
}
